/**
 * ...
 * @author HTML5
 */

function Radix() {}


Radix.sortInt = function( p_array )
{
	var tab = p_array;
	var buckets = null;
	var max = p_array.length;
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;
	var value = 0;
	var el = null;
	var curbuck = null;
	var shift = 0;
	
	if( p_array.length == 0 )
	{
		return p_array;
	}
	
	l = 0;
	j = 0;
	i = 0;
	
	while( i < 4  )
	{
		buckets = [];
		max = tab.length;
		j = 0;
		
		while( j < 512 )
		{
			buckets[j] = new Array();
			j++;
		}
		
		j = 0;
		
		
		while( j < max )
		{
			el = tab[j];
			value = ( el & (255 << (shift)) ) >> (shift);
			value = ( value > 0 ) ? 256 + value : 255 + value;
			buckets[value].push(el);
			j++;
		}
		

		
		j = 0;
		k = 0;
		l = 0;
		
		while( j < 512 )
		{
			curbuck = buckets[j];
			max = curbuck.length;
			
			k = 0;
			while( k < max )
			{
				tab[l] = curbuck[k];
				l++;
				k++;
			}
			j++;
		}
		
		shift+=8;
		i++;
	}
	
	
	
	return tab;
};

Radix.sortByProperty = function( p_array, p_prop )
{
	var tab = p_array;
	var buckets = null;
	var max = p_array.length;
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;
	var value = 0;
	var el = null;
	var curbuck = null;
	
	l = 0;
	j = 0;
	i = 0;
	
	
	if( p_array.length == 0 )
	{
		return p_array;
	}
	
	while( i < 4  )
	{
		
		
		buckets = [];
		max = tab.length;
		j = 0;
		
		while( j < 512 )
		{
			buckets[j] = new Array();
			j++;
		}
		
		j = 0;
		
		
		while( j < max )
		{
			el = tab[j];
			value = ( el[p_prop] & (255 << (i*8)) ) >> (i*8);
			value = ( value > 0 ) ? 256 + value : 255 + value;
			buckets[value].push(el);
			j++;
		}

		
		j = 0;
		k = 0;
		l = 0;
		
		while( j < 512 )
		{
			curbuck = buckets[j];
			max = curbuck.length;
			
			k = 0;
			while( k < max )
			{
				tab[l] = curbuck[k];
				l++;
				k++;
			}
			j++;
		}
		
		i++;
	}
	
	return tab;
};